
import ctypes
import sys

if len(sys.argv) != 2:
    print "Usage: %s <duty>\n" % sys.argv[0]
    sys.exit(-1)
duty = int(sys.argv[1])
if (duty < 0) or (duty > 255):
    print "Illegal duty cycle (%d) specified.\n" % duty
    sys.exit(-1)

SET_RA1 = 1
CLR_RA1 = 2
GET_RA2 = 3
SET_DUTY = 4

usb = ctypes.cdll.LoadLibrary('usb.dll')
usb.initialize()

buffer = ctypes.c_buffer(8)

dev = usb.open_device(0x6666, 0x0003, 0)
if dev<0:
    print "No matching device found...\n"
else:
    ret = usb.control_transfer(dev, 0x40, SET_DUTY, duty, 0, 0, buffer)
    if ret<0:
        print "Unable to send SET_DUTY vendor request.\n"
    usb.close_device(dev)
